﻿#include "CServer.h"
#include "ConfigMgr.h"
#include "RedisMgr.h"

int main()
{
	//读取配置文件config.ini
	ConfigMgr gCfgMgr;
	std::string gate_port_str = gCfgMgr["GateServer"]["Port"];
	unsigned short gate_port = atoi(gate_port_str.c_str());
	try {
		unsigned short port = static_cast<unsigned short>(gate_port);
		net::io_context ioc{1};  //先测试1个线程
		net::signal_set signals(ioc, SIGINT, SIGTERM);
		signals.async_wait([&ioc](const boost::system::error_code& ec, int sign) {
			if (ec) {
				return;
			}
			ioc.stop();
			});
		std::make_shared<CServer>(ioc,port)->Start();
		std::cout << "GateServer listen on port:" << port << std::endl;
		ioc.run();
	}
	catch (std::exception& exp) {
		std::cerr << "error:" << exp.what() << std::endl;
		return  -1;
	}
}
